package com.zpark.controller;

import com.zpark.exception.ResponException;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseStatus;

/**
 * @PackageName: com.zpark.controller
 * @ClassName: ExceptionController
 * @Description:
 * @author: RZS
 * @date: 2023/4/13  14:53
 */
@Controller
public class ExceptionController {

    @PostMapping("/def.do")
    public String defTest(){
        return "success";
    }

    @RequestMapping("/test2.do")
    public String test2(){
        throw new ResponException();
    }

    @RequestMapping("/t3.do")
    public String test3(){
        int num = 2 / 0;
        return "";
    }

    @ExceptionHandler(ArithmeticException.class)
    public String test3Exception(Model model, ArithmeticException e){
        model.addAttribute("msg", e.getStackTrace());
        return "error";
    }
}
